<?php
/**
 * Created by PhpStorm.
 * User: Frings
 * Date: 2016/12/12
 * Time: 15:21
 */
use yii\helpers\Url;

$web = Url::base();
$scriptUrl = \Yii::$app->request->scriptUrl;
?>

<script type="application/javascript">

    $(function ($) {

        instituion_add=$('#selectInstitution').treeAutocomplete({
            defaultText: '----请选择机构----',
            source: institutions,
            onSelected: function (element) {
                //新增子机构选择
                var department_div = $("#department_div");
                var html = "";
                html += '<div id="parent_department"></div>';

                department_div.html(html);
                var institution_code = element.getValue();
                var action = "<?=$scriptUrl?>" + "/common" + "/department-tree-handler";
                var data = {};
                data.institution_code = institution_code;
                requestJson(action, data, true, function (responseData) {

                    if (responseData.status == 0) {
                        department =$('#parent_department').treeAutocomplete({
                            defaultText: "--上级子机构(部门)--",
                            isShowCode: false,
                            source: responseData.data
                        });
                    }
                });

            }
        }).setValue(institutionCurent);

        //子机构管理员，导入页面，初始化子机构树
        if (!(institutionCurent == '' || institutionCurent == '0')) {
            var disabled = true;
            var department_selected = $("#departmentImport_div");
            var html_selected = "";
            html_selected += '<div id="inputdepartment_import"></div>';
            department_selected.html(html_selected);
            var institution_code = institutionCurent;
            var action = "<?=$scriptUrl?>" + "/common" + "/department-tree-handler";
            var data = {};
            data.institution_code = institution_code;
            requestJson(action, data, true, function (responseData) {
                department = $('#parent_department').treeAutocomplete({
                    defaultText: "--上级子机构(部门)--",
                    isShowCode: false,
                    source: responseData.data
                }).setValue('<?=$item['parent_code']?>');
            });
        }
    });

</script>


<div class="form-horizontal" id="modaledit_submit_form">
    <div class="form-group" style=" margin-top: 5px">
        <label class="control-label col-lg-3">机构：</label>
        <div class="col-lg-9" id="selectInstitution"></div>
        <label id='alert4' style="display: none;"><span style="color: red">请选择一个机构</span></label>
    </div>
    <div class="form-group" style=" margin-top: 5px">
        <label class="control-label col-lg-3">上级子机构(部门)：</label>
        <div class="col-lg-9" id="department_div">
            <div id="parent_department"></div>
        </div>
    </div>
    <div class="form-group" style=" margin-top: 5px">
        <label class="control-label col-lg-3">子机构(部门)编码：</label>
        <div class="col-lg-9">
            <label class="control-label"><?= $item != null ? $item['code_tree'] : '' ?></label>
        </div>
    </div>
    <div class="form-group" style=" margin-top: 5px">
        <input type="hidden" id="id" value="<?= $item != null ? $item['id'] : '' ?>">
        <label class="control-label col-lg-3">子机构(部门)名称：</label>
        <div class="col-lg-9">
            <input type="text" id="name" name="name" class="form-control"
                   value="<?= $item != null ? $item['name'] : '' ?>">
        </div>
    </div>
    <div class="form-group" style=" margin-top: 5px">
        <label class="control-label col-lg-3">描述：</label>
        <div class="col-lg-9">
            <input type="text" id="remark" name="remark" class="form-control"
                   value="<?= $item != null ? $item['remark'] : '' ?>">
        </div>
    </div>
</div>

